//
//  TLMyViewController.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/10/14.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//
#import "TLUserManger.h"

#import "TLMyViewController.h"

#import "LeanCloudFeedback.h"

#import "UIImage+Circle.h"

@interface TLMyViewController ()

@end

@implementation TLMyViewController

#pragma mark -- View Life Cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [AVOSUserManger updateUser];
    self.title = Nav_Img_Logo;
    [self showUserInfos];
}

#pragma mark --
- (void)showUserInfos{
    if([[TLUserManger sharedManger] hasUser])
    {
        [self.myHeaderBtn setBackgroundImage:[[[TLUserManger sharedManger] getUserHead] circleImageBordWidth:6.f] forState:UIControlStateNormal];
        
        NSDictionary *userInfo = [[TLUserManger sharedManger] getUserInfos];
        
        [self.nameButton setTitle:(NSString *)userInfo[@"username"] forState:UIControlStateNormal];
    }
    else
    {
        [self.myHeaderBtn setBackgroundImage:[UIImage imageNamed:@"DefaultHead"] forState:UIControlStateNormal];
        [self.nameButton setTitle:@"点击登录" forState:UIControlStateNormal];
    }
    
    // Do any additional setup after loading the view.
//    NSLog(@"%lf",self.myHeaderBtn.layer.frame.size.height/2);
//    self.myHeaderBtn.layer.cornerRadius = self.myHeaderBtn.bounds.size.width/2;
//    self.myHeaderBtn.layer.masksToBounds = YES;
//
//    self.myHeaderBtn.layer.borderWidth = 3.f;
}
#pragma mark -- Actions User
- (IBAction)loginTapped:(id)sender {
    
}
#pragma mark -- Actions Function
- (IBAction)showPlayRecord:(id)sender {
    
}

- (IBAction)showUserMessage:(id)sender {
    
}

- (IBAction)showFeedBackVC:(id)sender {
    
   /* LCUserFeedbackAgent *agent = [LCUserFeedbackAgent sharedInstance];
    
    agent.
    
    [agent showConversations:self title:nil contact:@"tech@gmapp.com"];
    */
    LCUserFeedbackViewController *feedbackViewController = [[LCUserFeedbackViewController alloc] init];
    feedbackViewController.navigationBarStyle = LCUserFeedbackNavigationBarStyleNone;
    feedbackViewController.contactHeaderHidden = YES;
    feedbackViewController.feedbackTitle = [AVUser currentUser].username;
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:feedbackViewController];
    
    navigationController.navigationBar.backgroundColor  = TintColor;
    
    [self presentViewController:navigationController animated:YES completion: ^{
        
    }];
}

- (IBAction)showChangePswVC:(id)sender {
    
}

#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (BOOL)shouldPerformSegueWithIdentifier:(nonnull NSString *)identifier sender:(nullable id)sender{
    if([[TLUserManger sharedManger] hasUser] && ((UIView *)sender).tag == 301)
    {
        [TLAlertHelper showAlertInView:self.navigationController.view title:@"退出当前用户?" cancleBtnTitle:@"取消" destructiveBtnTitle:nil completionWithAction:^(NSInteger index) {
            NSLog(@"选择了 %ld",index);
            if(index == 0)
            {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [[TLUserManger sharedManger] logout];
                    [self showUserInfos];
                });
            }
        }];
        
        return ![[TLUserManger sharedManger] hasUser];
    }
    
    return YES;
}

@end
